package com.cloud.salon.client.authority.service.impl;

import com.cloud.salon.common.base.response.Res;
import com.cloud.salon.common.crud.service.impl.CRUDServiceImpl;
import com.cloud.salon.client.authority.repository.AuthorityRepository;
import com.cloud.salon.client.authority.service.AuthorityService;
import com.cloud.salon.common.base.entity.authority.Authority;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description 权限Service实现类
 * @Author wolf--LZH
 * @CreateDate 2019/4/10 0010 下午 1:30
 */
@Service
public class AuthorityServiceImpl extends CRUDServiceImpl<Authority, AuthorityRepository> implements AuthorityService {

	@Autowired
	private AuthorityRepository repository;

	public Res<List<Authority>> findByIdList(List<Integer> ids) {
		return new Res(0, "查找成功", repository.findByIdIn(ids));
	}

	public Res<List<Authority>> findByRole(Integer roleId) {
		List<Authority> authorities = repository.findByRole(roleId);

		if(authorities != null)
			return new Res(0, "查找成功", authorities);
		else
			return new Res(-3, "查找失败");
	}

	public Res<List<Authority>> findByUser(Integer userId) {
		List<Authority> authorities = repository.findByUser(userId);

		if(authorities != null)
			return new Res(0, "查找成功", authorities);
		else
			return new Res(-3, "查找失败");
	}
}
